178 lines
5.8 KiB
C#
178 lines
5.8 KiB
C#
using System;
|
|
using SqlSugar;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
using ZR.Model;
|
|
using ZR.Model.Dto;
|
|
using ZR.Repository;
|
|
using ZR.Service.Business.IBusinessService;
|
|
using System.Linq;
|
|
using ZR.Service.mes.wms.IService;
|
|
using ZR.Model.MES.wms;
|
|
using ZR.Model.MES.wms.Dto;
|
|
|
|
namespace ZR.Service.mes.wms
|
|
{
|
|
/// <summary>
|
|
/// 毛坯库存库存变动记录表Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IWmBlankRecordService), ServiceLifetime = LifeTime.Transient)]
|
|
public class WmBlankRecordService : BaseService<WmBlankRecord>, IWmBlankRecordService
|
|
{
|
|
/// <summary>
|
|
/// 查询毛坯库存库存变动记录表列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<WmBlankRecordDto> GetList(WmBlankRecordQueryDto parm)
|
|
{
|
|
var predicate = Expressionable.Create<WmBlankRecord>();
|
|
|
|
var response = Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.ToPage<WmBlankRecord, WmBlankRecordDto>(parm);
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
public WmBlankRecord GetInfo(string Id)
|
|
{
|
|
var response = Queryable()
|
|
.Where(x => x.Id == Id)
|
|
.First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加毛坯库存库存变动记录表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public WmBlankRecord AddWmBlankRecord(WmBlankRecord model)
|
|
{
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改毛坯库存库存变动记录表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateWmBlankRecord(WmBlankRecord model)
|
|
{
|
|
//var response = Update(w => w.Id == model.Id, it => new WmBlankRecord()
|
|
//{
|
|
// BlankNum = model.BlankNum,
|
|
// ChangeQuantity = model.ChangeQuantity,
|
|
// Type = model.Type,
|
|
// Status = model.Status,
|
|
// Remark = model.Remark,
|
|
// CreatedBy = model.CreatedBy,
|
|
// CreatedTime = model.CreatedTime,
|
|
// UpdatedBy = model.UpdatedBy,
|
|
// UpdatedTime = model.UpdatedTime,
|
|
//});
|
|
//return response;
|
|
return Update(model, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加库存
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="fk_blank_inventory_id"></param>
|
|
/// <param name="change_quantity"></param>
|
|
/// <returns></returns>
|
|
public int AddInventory(string id, string fk_blank_inventory_id, int change_quantity,string username)
|
|
{
|
|
// 增加库存
|
|
int result=Context.Updateable<WmBlankInventory>()
|
|
.SetColumns(it => it.Quantity == it.Quantity + change_quantity)
|
|
.Where(it => it.Id == id)
|
|
.Where(it => it.BlankNum == fk_blank_inventory_id)
|
|
.ExecuteCommand();
|
|
if(result==1)
|
|
{
|
|
WmBlankRecord res = new WmBlankRecord();
|
|
res.Id= SnowFlakeSingle.Instance.NextId().ToString();
|
|
res.FkBlankInventoryId=fk_blank_inventory_id;
|
|
res.ChangeQuantity = change_quantity;
|
|
res.Type = 1;
|
|
res.Status = 1;
|
|
res.CreatedBy = username;
|
|
res.CreatedTime = DateTime.Now;
|
|
|
|
//填写库存记录
|
|
Context.Insertable(res).ExecuteCommand();
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除库存
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="fk_blank_inventory_id"></param>
|
|
/// <param name="change_quantity"></param>
|
|
/// <returns></returns>
|
|
public int DeleteInventory(string id, string fk_blank_inventory_id, int change_quantity, string username)
|
|
{
|
|
int resut = 0;
|
|
UseTran2(() =>
|
|
{
|
|
WmBlankInventory record = Context.Queryable<WmBlankInventory>()
|
|
.Where(it => it.Id == id)
|
|
.Where(it => it.BlankNum == fk_blank_inventory_id).First();
|
|
|
|
|
|
if (record != null && record.Quantity < change_quantity)
|
|
{
|
|
resut = 0 - change_quantity;
|
|
}
|
|
else if (record == null)
|
|
{
|
|
resut = -1;
|
|
}
|
|
else
|
|
{
|
|
resut = Context.Updateable<WmBlankInventory>()
|
|
.SetColumns(it => it.Quantity == it.Quantity - change_quantity)
|
|
.Where(it => it.Id == id)
|
|
.Where(it => it.FkPaintId == fk_blank_inventory_id)
|
|
.ExecuteCommand();
|
|
|
|
if (resut == 1)
|
|
{
|
|
WmBlankRecord res = new WmBlankRecord();
|
|
res.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
|
res.FkBlankInventoryId = fk_blank_inventory_id;
|
|
res.ChangeQuantity = change_quantity;
|
|
res.Type = 2;
|
|
res.Status = 1;
|
|
res.CreatedBy = username;
|
|
res.CreatedTime = DateTime.Now;
|
|
|
|
//填写库存记录
|
|
Context.Insertable(res).ExecuteCommand();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
});
|
|
return resut;
|
|
}
|
|
|
|
}
|
|
} |