新增 GetLocationOption 接口,完善 Controller、Service 层及 MmLocationOption DTO,实现库位下拉数据获取。修正仓库或库位不存在时的错误提示信息。
366 lines
13 KiB
C#
366 lines
13 KiB
C#
using DOAN.Model.BZFM;
|
|
using DOAN.Model.BZFM.Dto;
|
|
using DOAN.Model.Mobile.Dto;
|
|
using DOAN.Repository;
|
|
using DOAN.Service.BZFM.IBZFMService;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
|
|
namespace DOAN.Service.BZFM
|
|
{
|
|
/// <summary>
|
|
/// 库存表Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IMmInventoryService), ServiceLifetime = LifeTime.Transient)]
|
|
public class MmInventoryService : BaseService<MmInventory>, IMmInventoryService
|
|
{
|
|
/// <summary>
|
|
/// 查询库存表列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<MmInventoryDto> GetList(MmInventoryQueryDto parm)
|
|
{
|
|
var predicate = QueryExp(parm);
|
|
|
|
var response = Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.ToPage<MmInventory, MmInventoryDto>(parm);
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
public MmInventory GetInfo(int Id)
|
|
{
|
|
var response = Queryable()
|
|
.Where(x => x.Id == Id)
|
|
.First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加库存表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public MmInventory AddMmInventory(MmInventory model)
|
|
{
|
|
return Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改库存表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateMmInventory(MmInventory model)
|
|
{
|
|
return Update(model, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询导出表达式
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
private static Expressionable<MmInventory> QueryExp(MmInventoryQueryDto parm)
|
|
{
|
|
var predicate = Expressionable.Create<MmInventory>()
|
|
.AndIF(!string.IsNullOrEmpty(parm.WarehouseCode), m => m.WarehouseCode.Contains(parm.WarehouseCode))
|
|
.AndIF(!string.IsNullOrEmpty(parm.MaterialCode), m => m.MaterialCode.Contains(parm.MaterialCode))
|
|
;
|
|
|
|
return predicate;
|
|
}
|
|
|
|
public List<MmMaterialOption> GetMaterialOption()
|
|
{
|
|
try
|
|
{
|
|
return Context.Queryable<MmMaterial>()
|
|
.Where(it => it.Status == "启用")
|
|
.Select(it => new MmMaterialOption
|
|
{
|
|
MaterialCode = it.MaterialCode,
|
|
MaterialName = it.MaterialName,
|
|
CategoryCode = it.CategoryCode,
|
|
Specification = it.Specification
|
|
})
|
|
.ToList();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
public List<MmLocationOption> GetLocationOption()
|
|
{
|
|
try
|
|
{
|
|
return Context.Queryable<MmLocation>()
|
|
.Where(it => it.Status == "启用")
|
|
.Select(it => new MmLocationOption
|
|
{
|
|
WarehouseCode = it.WarehouseCode,
|
|
WarehouseName = it.WarehouseName,
|
|
LocationCode = it.LocationCode,
|
|
LocationName = it.LocationName,
|
|
LocationType = it.LocationType
|
|
})
|
|
.ToList();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public List<MmTransactionOption> GetTransactionOption()
|
|
{
|
|
try
|
|
{
|
|
return Context.Queryable<MmTransactionType>()
|
|
.Where(it => it.Status == "启用")
|
|
.Select(it => new MmTransactionOption
|
|
{
|
|
Label = it.TypeName,
|
|
Value = it.TypeCode
|
|
})
|
|
.ToList();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public string CreateInboundReceipt(InboundReceiptDto parm)
|
|
{
|
|
try
|
|
{
|
|
DateTime nowDate = DateTime.Now;
|
|
// 验证信息
|
|
// 校验蓝单红单
|
|
int receiptType = parm.ReceiptType;
|
|
decimal CurrentQty = parm.Quantity;
|
|
if(receiptType == 1)
|
|
{
|
|
CurrentQty = Math.Abs(CurrentQty);
|
|
}
|
|
else
|
|
{
|
|
CurrentQty = - Math.Abs(CurrentQty);
|
|
}
|
|
|
|
MmMaterial mmMaterial = Context.Queryable<MmMaterial>()
|
|
.Where(it => it.MaterialCode == parm.MaterialCode)
|
|
.First();
|
|
if(mmMaterial == null)
|
|
{
|
|
return "物料不存在!";
|
|
}
|
|
|
|
// 验证信息
|
|
MmLocation mmLocation = Context.Queryable<MmLocation>()
|
|
.Where(it => it.WarehouseCode == parm.WarehouseCode)
|
|
.Where(it => it.LocationCode == parm.LocationCode)
|
|
.First();
|
|
if (mmLocation == null)
|
|
{
|
|
return "仓库编码或库位编码不存在!";
|
|
}
|
|
bool hasInventory = true;
|
|
MmInventory mmInventory = Context.Queryable<MmInventory>()
|
|
.Where(it => it.MaterialCode == parm.MaterialCode)
|
|
.Where(it => it.BatchNo == parm.BatchNo)
|
|
.Where(it => it.LocationCode == parm.LocationCode)
|
|
.First();
|
|
if(mmInventory == null)
|
|
{
|
|
hasInventory = false;
|
|
}
|
|
// 启用事务
|
|
Context.Ado.BeginTran();
|
|
|
|
if (!hasInventory)
|
|
{
|
|
|
|
// 添加库存
|
|
MmInventory newInventory = new MmInventory()
|
|
{
|
|
MaterialCode = mmMaterial.MaterialCode,
|
|
LocationCode = mmLocation.LocationCode,
|
|
LocationName = mmLocation.LocationName,
|
|
WarehouseCode = mmLocation.WarehouseCode,
|
|
WarehouseName = mmLocation.WarehouseName,
|
|
BatchNo = parm.BatchNo,
|
|
CurrentQty = parm.Quantity,
|
|
Unit = parm.Unit,
|
|
ExpiryDate = parm.ExpiryDate,
|
|
LastUpdatedTime = null,
|
|
ProductionDate = parm.ProductionDate,
|
|
CreatedTime = nowDate
|
|
};
|
|
Context.Insertable(newInventory).ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
Context.Updateable(mmInventory)
|
|
.SetColumns(it => it.CurrentQty == it.CurrentQty + CurrentQty)
|
|
.ExecuteCommand();
|
|
}
|
|
// 插入记录
|
|
MmRecordInbound newRecord = new MmRecordInbound()
|
|
{
|
|
// TODO处理入库单号自动累计增加
|
|
InboundNo = "RK" + DateTime.Now.ToString("yyyyMMdd"),
|
|
BatchNo = parm.BatchNo,
|
|
Operator = parm.Operator,
|
|
MaterialCode = mmMaterial.MaterialCode,
|
|
MaterialName = mmMaterial.MaterialName,
|
|
LocationCode = mmLocation.LocationCode,
|
|
LocationName = mmLocation.LocationName,
|
|
WarehouseCode = mmLocation.WarehouseCode,
|
|
WarehouseName = mmLocation.WarehouseName,
|
|
Quantity = parm.Quantity,
|
|
Unit = parm.Unit,
|
|
SupplierCode = parm.SupplierCode,
|
|
SupplierName = parm.SupplierName,
|
|
ProductionDate = parm.ProductionDate,
|
|
ExpiryDate = parm.ExpiryDate,
|
|
CreatedTime = nowDate,
|
|
TransactionType = parm.TransactionType,
|
|
Remarks = parm.Remarks
|
|
};
|
|
Context.Insertable(newRecord).ExecuteCommand();
|
|
|
|
Context.Ado.CommitTran();
|
|
return "ok";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// 回滚操作
|
|
Context.Ado.RollbackTran();
|
|
return ex.Message;
|
|
}
|
|
}
|
|
|
|
public string CreateOutboundReceipt(OutboundReceiptDto parm)
|
|
{
|
|
try
|
|
{
|
|
DateTime nowDate = DateTime.Now;
|
|
// 验证信息
|
|
// 校验蓝单红单
|
|
int receiptType = parm.ReceiptType;
|
|
decimal CurrentQty = parm.Quantity;
|
|
if (receiptType == 1)
|
|
{
|
|
CurrentQty = Math.Abs(CurrentQty);
|
|
}
|
|
else
|
|
{
|
|
CurrentQty = -Math.Abs(CurrentQty);
|
|
}
|
|
|
|
MmMaterial mmMaterial = Context.Queryable<MmMaterial>()
|
|
.Where(it => it.MaterialCode == parm.MaterialCode)
|
|
.First();
|
|
if (mmMaterial == null)
|
|
{
|
|
return "物料不存在!";
|
|
}
|
|
|
|
// 验证信息
|
|
|
|
MmLocation mmLocation = Context.Queryable<MmLocation>()
|
|
.Where(it => it.WarehouseCode == parm.WarehouseCode)
|
|
.Where(it => it.LocationCode == parm.LocationCode)
|
|
.First();
|
|
if (mmLocation == null)
|
|
{
|
|
return "仓库编码或库位编码不存在!";
|
|
}
|
|
bool hasInventory = true;
|
|
MmInventory mmInventory = Context.Queryable<MmInventory>()
|
|
.Where(it => it.MaterialCode == parm.MaterialCode)
|
|
.Where(it => it.BatchNo == parm.BatchNo)
|
|
.Where(it => it.LocationCode == parm.LocationCode)
|
|
.First();
|
|
if (mmInventory == null)
|
|
{
|
|
hasInventory = false;
|
|
}
|
|
// 启用事务
|
|
Context.Ado.BeginTran();
|
|
|
|
if (!hasInventory)
|
|
{
|
|
|
|
// 添加库存
|
|
MmInventory newInventory = new MmInventory()
|
|
{
|
|
MaterialCode = mmMaterial.MaterialCode,
|
|
LocationCode = mmLocation.LocationCode,
|
|
LocationName = mmLocation.LocationName,
|
|
WarehouseCode = mmLocation.WarehouseCode,
|
|
WarehouseName = mmLocation.WarehouseName,
|
|
BatchNo = parm.BatchNo,
|
|
CurrentQty = - parm.Quantity,
|
|
Unit = parm.Unit,
|
|
LastUpdatedTime = null,
|
|
CreatedTime = nowDate
|
|
};
|
|
Context.Insertable(newInventory).ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
Context.Updateable(mmInventory)
|
|
.SetColumns(it => it.CurrentQty == it.CurrentQty - CurrentQty)
|
|
.ExecuteCommand();
|
|
}
|
|
// 插入记录
|
|
MmRecordOutbound newRecord = new MmRecordOutbound()
|
|
{
|
|
// TODO处理出库单号自动累计增加
|
|
OutboundNo = "CK" + DateTime.Now.ToString("yyyyMMdd"),
|
|
BatchNo = parm.BatchNo,
|
|
Operator = parm.Operator,
|
|
MaterialCode = mmMaterial.MaterialCode,
|
|
MaterialName = mmMaterial.MaterialName,
|
|
LocationCode = mmLocation.LocationCode,
|
|
LocationName = mmLocation.LocationName,
|
|
WarehouseCode = mmLocation.WarehouseCode,
|
|
WarehouseName = mmLocation.WarehouseName,
|
|
Quantity = parm.Quantity,
|
|
Unit = parm.Unit,
|
|
CreatedTime = nowDate,
|
|
TransactionType = parm.TransactionType,
|
|
Remarks = parm.Remarks
|
|
};
|
|
Context.Insertable(newRecord).ExecuteCommand();
|
|
Context.Ado.CommitTran();
|
|
return "ok";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// 回滚操作
|
|
Context.Ado.RollbackTran();
|
|
return ex.Message;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |