203 lines
8.4 KiB
C#
203 lines
8.4 KiB
C#
using System;
|
|
using SqlSugar;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
using DOAN.Model;
|
|
using DOAN.Model.Dto;
|
|
using DOAN.Repository;
|
|
using DOAN.Model.MES.dev.Dto;
|
|
using DOAN.Model.MES.dev;
|
|
using System.Linq;
|
|
using DOAN.Service.MES.dev.IService;
|
|
namespace DOAN.Service.MES.dev
|
|
{
|
|
/// <summary>
|
|
/// 库存信息表Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IDevicePartsInventoryService), ServiceLifetime = LifeTime.Transient)]
|
|
public class DevicePartsInventoryService : BaseService<DevicePartsInventory>, IDevicePartsInventoryService
|
|
{
|
|
/// <summary>
|
|
/// 查询库存信息表列表
|
|
/// </summary>
|
|
/// <param name="parm">库存信息表查询对象,包含库存位置 code、备件名称、备件编号和描述信息等查询条件</param>
|
|
/// <returns>分页后的库存信息表数据</returns>
|
|
public PagedInfo<DevicePartsInventoryDto2> GetList(DevicePartsInventoryQueryDto parm)
|
|
{
|
|
/*int[] LocationIdArray = null;
|
|
if (!string.IsNullOrEmpty(parm.locationCode))
|
|
{
|
|
LocationIdArray= Context.Queryable<DevicePartsStorageLocations>().Where(it => it.LocationCode == parm.locationCode)
|
|
.Select(it => it.LocationId).ToArray();
|
|
}
|
|
int[] PartIdArray =null;
|
|
if (!string.IsNullOrEmpty(parm.partName) && !string.IsNullOrEmpty(parm.partCode))
|
|
{
|
|
PartIdArray = Context.Queryable<DeviceSpareParts>()
|
|
.Where(it => it.PartName.Contains(parm.partName) && it.PartCode.Contains(parm.partCode))
|
|
.Select(it => it.PartId).ToArray();
|
|
}else if (!string.IsNullOrEmpty(parm.partName))
|
|
{
|
|
PartIdArray = Context.Queryable<DeviceSpareParts>()
|
|
.Where(it => it.PartName.Contains(parm.partName) )
|
|
.Select(it => it.PartId).ToArray();
|
|
}else if (!string.IsNullOrEmpty(parm.partCode))
|
|
{
|
|
PartIdArray = Context.Queryable<DeviceSpareParts>()
|
|
.Where(it => it.PartCode.Contains(parm.partCode))
|
|
.Select(it => it.PartId).ToArray();
|
|
}*/
|
|
|
|
var result = Queryable().LeftJoin<DeviceSpareParts>((r, s) => r.PartId == s.PartId)
|
|
.WhereIF(!string.IsNullOrEmpty(parm.locationCode), (r, s) => r.Location.Contains(parm.locationCode))
|
|
.WhereIF(!string.IsNullOrEmpty(parm.partName), (r, s) => s.PartName.Contains(parm.partName))
|
|
.WhereIF(!string.IsNullOrEmpty(parm.partCode), (r, s) => s.PartCode.Contains(parm.partCode))
|
|
// 添加描述搜索条件
|
|
.WhereIF(!string.IsNullOrEmpty(parm.description), (r, s) => s.Description.Contains(parm.description))
|
|
.Select((r, s) => new DevicePartsInventoryDto2(), true)
|
|
.ToPage_NO_Convert(parm);
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="InventoryId"></param>
|
|
/// <returns></returns>
|
|
public DevicePartsInventory GetInfo(int InventoryId)
|
|
{
|
|
var response = Queryable()
|
|
.Where(x => x.InventoryId == InventoryId)
|
|
.First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加库存信息表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public DevicePartsInventory AddDevicePartsInventory(DevicePartsInventory model)
|
|
{
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改库存信息表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateDevicePartsInventory(DevicePartsInventory model)
|
|
{
|
|
//var response = Update(w => w.InventoryId == model.InventoryId, it => new DevicePartsInventory()
|
|
//{
|
|
// Quantity = model.Quantity,
|
|
// Location = model.Location,
|
|
// LastInventoryCheck = model.LastInventoryCheck,
|
|
// CreatedAt = model.CreatedAt,
|
|
// UpdatedAt = model.UpdatedAt,
|
|
//});
|
|
//return response;
|
|
return Update(model, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 入库
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public bool EntryInventory(DevicePartsInventoryDto parm,string admin,int SupplierId)
|
|
{
|
|
|
|
DevicePartsTransactions devicePartsTransactions = new DevicePartsTransactions();
|
|
devicePartsTransactions.PartId= parm.PartId;
|
|
devicePartsTransactions.TransactionType = "入库";
|
|
devicePartsTransactions.Quantity = parm.Quantity;
|
|
devicePartsTransactions.TransactionDate = DateTime.Now;
|
|
|
|
devicePartsTransactions.CreatedBy = admin;
|
|
devicePartsTransactions.SupplierId = SupplierId;
|
|
//要么新增,要么修改
|
|
bool isExist = Context.Queryable<DevicePartsInventory>()
|
|
.Where(it => it.PartId == parm.PartId && it.Location == parm.Location).Any();
|
|
if (isExist)
|
|
{
|
|
devicePartsTransactions.Remarks = "有库存入库";
|
|
Context.Insertable(devicePartsTransactions).ExecuteCommand();
|
|
|
|
|
|
return Context.Updateable<DevicePartsInventory>()
|
|
.SetColumns(it=>it.Quantity==it.Quantity+parm.Quantity)
|
|
.SetColumns(it=>it.UpdatedAt==DateTime.Now)
|
|
.Where(it=>it.PartId==parm.PartId&&it.Location==parm.Location)
|
|
.ExecuteCommand()>0;
|
|
}
|
|
else
|
|
{
|
|
devicePartsTransactions.Remarks = "无库存入库";
|
|
Context.Insertable(devicePartsTransactions).ExecuteCommand();
|
|
|
|
|
|
DevicePartsInventory inventory = new DevicePartsInventory
|
|
{
|
|
PartId = parm.PartId,
|
|
Quantity = parm.Quantity,
|
|
Location = parm.Location,
|
|
CreatedAt = DateTime.Now,
|
|
|
|
};
|
|
return Context.Insertable(inventory).ExecuteCommand()>0;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 出库
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public bool OutInventory(DevicePartsInventoryDto parm,string admin)
|
|
{
|
|
DevicePartsTransactions devicePartsTransactions = new DevicePartsTransactions();
|
|
devicePartsTransactions.PartId= parm.PartId;
|
|
devicePartsTransactions.TransactionType = "出库";
|
|
devicePartsTransactions.Quantity = parm.Quantity;
|
|
devicePartsTransactions.TransactionDate = DateTime.Now;
|
|
|
|
devicePartsTransactions.CreatedBy = admin;
|
|
|
|
Context.Insertable(devicePartsTransactions).ExecuteCommand();
|
|
return Context.Updateable<DevicePartsInventory>()
|
|
.SetColumns(it=>it.Quantity==it.Quantity-parm.Quantity)
|
|
.SetColumns(it=>it.UpdatedAt==DateTime.Now)
|
|
.Where(it=>it.PartId==parm.PartId&&it.Location==parm.Location)
|
|
.ExecuteCommand()>0;
|
|
}
|
|
public bool CheckInventory(DevicePartsInventoryDto parm,string admin)
|
|
{
|
|
DevicePartsTransactions devicePartsTransactions = new DevicePartsTransactions();
|
|
devicePartsTransactions.PartId= parm.PartId;
|
|
devicePartsTransactions.TransactionType = "盘点";
|
|
devicePartsTransactions.Quantity = parm.Quantity;
|
|
devicePartsTransactions.TransactionDate = DateTime.Now;
|
|
|
|
devicePartsTransactions.CreatedBy = admin;
|
|
|
|
Context.Insertable(devicePartsTransactions).ExecuteCommand();
|
|
return Context.Updateable<DevicePartsInventory>()
|
|
.SetColumns(it=>it.Quantity==parm.Quantity)
|
|
.SetColumns(it=>it.UpdatedAt==DateTime.Now)
|
|
.SetColumns(it=>it.LastInventoryCheck==DateTime.Now)
|
|
.Where(it=>it.PartId==parm.PartId&&it.Location==parm.Location)
|
|
.ExecuteCommand()>0;
|
|
}
|
|
|
|
|
|
}
|
|
} |